# Maintainer: Alexey Pavlov <alexpux@gmail.com>
# Contributor: Ray Donnelly <mingw.android@gmail.com>

_realname=libtool
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=2.4.6
pkgrel=18
pkgdesc="A system independent dlopen wrapper for GNU libtool (mingw-w64)"
arch=('any')
url="https://www.gnu.org/software/libtool"
license=("GPL")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc")
options=('staticlibs' 'strip')
source=("https://ftp.gnu.org/pub/gnu/libtool/${_realname}-${pkgver}.tar.xz"{,.sig}
        #https://alpha.gnu.org/gnu/libtool/${_realname}-${pkgver}.tar.xz{,.sig}
        0002-cygwin-mingw-Create-UAC-manifest-files.mingw.patch
        0003-Pass-various-runtime-library-flags-to-GCC.mingw.patch
        0005-Fix-seems-to-be-moved.patch
        0006-Fix-strict-ansi-vs-posix.patch
        0007-fix-cr-for-awk-in-configure.all.patch
        0008-tests.patch
        0011-Pick-up-clang_rt-static-archives-compiler-internal-l.patch
        0012-Prefer-response-files-over-linker-scripts-for-mingw-.patch
        0013-Allow-statically-linking-compiler-support-libraries-.patch)
sha256sums=('7c87a8c2c8c0fc9cd5019e402bed4292462d00a718a7cd5f11218153bf28b26f'
            'SKIP'
            'fe8b80efd34f9385220ebc90aaec945e44de8c343c75719d6ac0d4e472a6eed5'
            '4f452cc104d110b4745d70e9bfc72617183ef97b25595b2675ab681d6c9517c2'
            'dc39fbe066958178f96108f07db62b48b9339efddf2c21f800ff8d67110ca393'
            '6a94ada08b0a0aa36240efd9ccb826e22ab94ef0969270f2edb8be344dc8c62b'
            'd96beecfc5d15f94ce46bbe0e89d6e6fdb973a25ad6be98c30504b58453792c1'
            'f00b44b49f83b20d4fbde89253666d0eb769172cfd711110f1be6a175294cb27'
            'c727b2b017163cfdeca60820d3cff2dac8968c5630745602b150f92b159af313'
            'c95a65e890b1ae6362807abc66809e72cf81aeea5f9f556e38f9752f974bf435'
            '8069e887aeeab7491f15e00547fa66d9b9e86407f5a23f37a6d8c7d165de752e')

validpgpkeys=('CFE2BE707B538E8B26757D84151308092983D606') #Gary Vaughan (Free Software Developer) <gary@vaughan.pe>

prepare() {
  cd ${srcdir}/${_realname}-${pkgver}
  patch -p1 -i ${srcdir}/0002-cygwin-mingw-Create-UAC-manifest-files.mingw.patch
  patch -p1 -i ${srcdir}/0003-Pass-various-runtime-library-flags-to-GCC.mingw.patch
  patch -p1 -i ${srcdir}/0005-Fix-seems-to-be-moved.patch
  patch -p1 -i ${srcdir}/0006-Fix-strict-ansi-vs-posix.patch
  patch -p1 -i ${srcdir}/0007-fix-cr-for-awk-in-configure.all.patch
  patch -p1 -i ${srcdir}/0008-tests.patch
  patch -p1 -i ${srcdir}/0011-Pick-up-clang_rt-static-archives-compiler-internal-l.patch
  patch -p1 -i ${srcdir}/0012-Prefer-response-files-over-linker-scripts-for-mingw-.patch
  patch -p1 -i ${srcdir}/0013-Allow-statically-linking-compiler-support-libraries-.patch
}

build() {
  [[ -d "${srcdir}/build-${MINGW_CHOST}" ]] && rm -rf "${srcdir}/build-${MINGW_CHOST}"
  mkdir -p ${srcdir}/build-${MINGW_CHOST} && cd ${srcdir}/build-${MINGW_CHOST}
  ../${_realname}-${pkgver}/configure \
      --prefix=${MINGW_PREFIX} \
      --build=${MINGW_CHOST} \
      --host=${MINGW_CHOST} \
      --target=${MINGW_CHOST}
  make
}

#check() {
#  cd ${srcdir}/build-${MINGW_CHOST}
#  make check
#}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make DESTDIR="${pkgdir}" install
  # Because libtool will have queried native compilers,
  # it'll contain native paths, so sed them back again.
  local MINGW_PREFIX_W=$(cygpath -m "${MINGW_PREFIX}")
  sed -i "s#${MINGW_PREFIX_W}#${MINGW_PREFIX}#g" "${pkgdir}${MINGW_PREFIX}"/bin/libtool
}
